package org.study;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

public class LookSupportDemo {

    public volatile boolean run = false;

    /**
     * 线程中断的使用
     *
     *
     */
    public void interrupt() {

        Thread th = new Thread(() -> {

            while (run) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if (interrupted) {
                    System.out.println("线程已经被中断");
                    run = false;
                } else {
                    System.out.println("线程在运行中...");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        // 这里捕捉异常后会将中断标志字重置为false
                        System.out.println("线程被中断，中断状态清零，现在状态为：" + Thread.currentThread().isInterrupted());
                        Thread.currentThread().interrupt(); // 这里再中断一次
                    }
                }
            }
        });
        th.start();
        try {
            Thread.sleep(3);
        } catch (InterruptedException e) {
            System.out.println("线程被中断");
        }
        th.interrupt();
    }


    public void lock() {
        int x = 0x000A;
        x |= x >>> 1;
        x |= x >>> 2;
        x |= x >>> 4;
        x |= x >>> 8;
        x |= x >>> 16;
        System.out.println(x);
    }

    public static void main(String[] args) {
        /** 线程中断方法练习 */
//        LookSupportDemo lsd = new LookSupportDemo();
//        lsd.run = true;
//        lsd.interrupt();
//        LookSupportDemo lsd = new LookSupportDemo();
//        lsd.lock();
       ConcurrentHashMap hashMap = new ConcurrentHashMap(20);
       hashMap.put("122", 122);
       hashMap.put("123", 123);
       hashMap.put("124", 124);
       hashMap.put("125", 125);
       hashMap.put("126", 126);
       hashMap.put("127", 127);
       hashMap.put("128", 128);
       hashMap.put("129", 128);
       hashMap.put("130", 128);
       hashMap.put("131", 128);
       hashMap.put("132", 128);
       hashMap.put("133", 128);
       hashMap.put("134", 128);
       hashMap.put("135", 128);
       hashMap.put("136", 128);
       hashMap.put("137", 128);
       hashMap.put("138", 128);
       hashMap.put("139", 128);
       hashMap.put("140", 128);
       hashMap.put("141", 128);
       hashMap.put("142", 128);
       hashMap.put("143", 128);
       hashMap.put("144", 128);
       hashMap.put("145", 128);
       hashMap.put("146", 128);
       hashMap.put("147", 128);
       hashMap.put("148", 128);
       hashMap.put("149", 128);
       hashMap.put("150", 128);

       System.out.println(Integer.toBinaryString(48694));
    }
}
